/**
 * Created by wangchun on 15/9/16.
 */
define(function (require, exports, module) {

    var global=require("js/global");//加载全局js
    var dialog=require("js/dialog");//加载对话框
    module.exports = function(app){
        //添加页面控制器的ctrl
        app.controller('configTableListCtrl', ['$scope','$state','requestService','$sce', function($scope,$state,requestService,$sce) {
            //自动生成代码
            $scope.autoCode=function(module){
                var url="/config/table/code.html"
                requestService.getData(url,{"module":module}).success(function(response){
                    if(response!=null && response.error!='0'){
                        return dialog.alert('代码生成失败：'+response.error+"-"+response.info);
                    }
                    dialog.alert('代码生成成功');
                });
            }
            //代码下载
            $scope.table={};
            $scope.table.downURL="";
            $scope.downCode=function(module){
                var url=G.path.moduleTemplatePath+"/table/down.html?module="+module

                $scope.table.downURL=$sce.trustAsResourceUrl(url);
            }
            $scope.tableDelete=function(module,tableName){
                var url="/config/table/delete.html";
                requestService.postData(url,{"module":module,"name":tableName}).success(function(response){
                    if(response!=null && response.error!='0'){
                        return dialog.alert('删除表失败：'+response.error+"-"+response.info);
                    }
                    dialog.alert('删除表成功');
                    $state.go("tableList",{"module":module}, {reload: true});
                });
            }
        }]);
    }

});
